package com.du.stutestsys.controller.Administrator;

import com.du.stutestsys.controller.BaseControler;
import com.du.stutestsys.entity.ClassMag;
import com.du.stutestsys.entity.ClassTeacher;
import com.du.stutestsys.entity.SysUser;
import com.du.stutestsys.service.Administrator.ClassMagService;
import com.du.stutestsys.util.DuUtil;
import com.du.stutestsys.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
public class ClassMagController extends BaseControler {
    @Autowired
    ClassMagService classMagService;
    @PostMapping("admin/addClassMag")
    public String addClassMag(@RequestBody ClassMag classMag, @RequestParam List<ClassMag> classMagList){
        boolean b = classMagService.addClassMagAndTeacher(classMag, classMagList);
        return DuUtil.success(b).toJSONString();
    }


    @PostMapping("admin/updateClassTeacher")
    public String updateClassTeacher(@RequestBody ClassMag classMag, @RequestParam Map<SysUser, SysUser> teachers){
        boolean b = classMagService.updateClassTeacher(classMag, teachers);
        return DuUtil.success(b).toJSONString();
    }


    public String updateClassGrade(){
        boolean b = classMagService.updateClassGrade();
        return DuUtil.success(b).toJSONString();
    }

    @GetMapping("admin/selectClassMag")
    public String selectClassMag(@RequestBody ClassMag classMag){
        PageUtil pageUtil = DuUtil.setPageUtil(classMag,0,10);
        List<ClassMag> classMagList = classMagService.selectClassMag(classMag);
        return DuUtil.success(classMagList.size() > 0,classMagList,classMagList+"",pageUtil).toJSONString();
    }

    @PostMapping("admin/relieveClass")
    public String relieveClass(@RequestBody List<Long> longList){
        boolean b = classMagService.relieveClass(longList);
        return DuUtil.success(b).toJSONString();
    }

    @PostMapping("admin/duTest")
    public String duTestMS(@RequestBody List<Long> longList){
        boolean b = classMagService.relieveClass(longList);
        return DuUtil.success(b).toJSONString();
    }


}
